<template>
	<view class="me-box">
		<TopBar :indexflag="true" :combakflag="false" :lang="true" :bottom="true" :title="$t('Me')"
			:barstyle="colortopic()">
		</TopBar>
		<view class="me-header">
			<view class="user-box">
				<view class="avartar">
					<image :src="getImgSrc(Userinfo.avatar)" mode=""></image>
				</view>
				<view class="username">ID:{{Userinfo.id}}</view>
				<view class="time" v-if="viptime!=null && viptime>0">{{$t('UseExpires')}} {{viptime}} {{$t('Sky')}}
				</view>
				<view class="time" v-if="viptime==0">{{$t('EndUsageTime')}}</view>
				<view class="time" v-if="viptime<0">{{$t('TimeExceeded')}} {{Math.abs(viptime)}} {{$t('GoBeyond')}}
				</view>
			</view>
		</view>
		<view class="menu-box">
			<view class="top-menu">
				<view class="item" v-for="(item,index) in top_menu" :key="index"
					@click="changemenu(item.url,item.name)">
					<u-icon :name="item.icon" :color="colortopic()" size="26"></u-icon>
					<text class="item-title">{{$t(item.name)}}</text>
				</view>
			</view>
			<view class="footer-menu">
				<view class="" v-for="(item,index) in footer_menu" :key="index" @click="changemenu(item.url,item.name)">
					<button v-if="item.name=='Contact'" open-type="contact" class="item">
						<view class="title">
							<u-icon :name="item.icon" :color="colortopic()" size="26"></u-icon>
							<text>{{$t(item.name)}}</text>
						</view>
						<view class="icon-box">
							<u-icon name="arrow-right" color="#fff" size="16"></u-icon>
						</view>
					</button>
					<view class="item" v-if="item.name!='Contact'">
						<view class="title">
							<u-icon :name="item.icon" :color="colortopic()" size="26"></u-icon>
							<text>{{$t(item.name)}}</text>
						</view>
						<view class="icon-box">
							<u-icon name="arrow-right" color="#fff" size="16"></u-icon>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-popup :show="popshow" mode="center" :round="10" @close="popshow=false" @open="popshow=true">
			<view class="pop-box">
				<u-icon name="error-circle-fill" :color="colortopic()" size="35"></u-icon>
				<view class="time">{{$t('EndUsageTime')}}</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import Contact from "@/components/Contact.vue"
	export default {
		components: {
			Contact
		},
		data() {
			return {
				top_menu: [{
						name: 'MyOrder',
						icon: 'order',
						url: '/pages/me/meorder'
					},
					{
						name: 'DeliveryAddress',
						icon: 'map',
						url: ''
					},
					{
						name: 'PersonalInformation',
						icon: 'account',
						url: ''
					}
				],
				footer_menu: [{
						name: 'Contact',
						icon: 'kefu-ermai',
						url: 'contact'
					},
					{
						name: 'MyRestaurant',
						icon: 'home',
						url: '/pages/boos/main'
					},
					{
						name: 'MyServe',
						icon: 'man-add',
						url: '/pages/employee/main'
					},
					{
						name: 'AboutUs',
						icon: 'error-circle',
						url: '/pages/me/aboutus'
					},
				],
				viptime: null,
				popshow: false,
				mydata: {
					mobile: '17690927591',
					wechat: '17690927591'
				},
			}
		},
		onShow() {
			uni.hideTabBar({
				animation: false
			})

		},
		computed: {
			i18nLocale() {
				return this.$i18n.locale;
			},
			Userinfo() {
				return this.$store.state.userinfo;
			},
		},
		mounted() {
			if (this.$store.state.shoptoken && this.$store.state.shopinfo.expired_at) {
				this.viptime = parseInt(this.daysBetweenDates(new Date(), this.$store.state.shopinfo.expired_at))
				console.log(this.viptime, '+++++')
				if (this.viptime == 0) {
					this.popshow = true;
				}
			}

		},
		methods: {
			changemenu(url, name) {
				if (url) {
					if (name == 'MyRestaurant') {
						if (this.$store.state.shoptoken) {
							uni.navigateTo({
								url: url
							})
						} else {
							uni.navigateTo({
								url: '/pages/main/bind?type=' + 'shop'
							})
						}

					} else if (name == 'MyServe') {
						if (this.$store.state.employeetoken) {
							uni.navigateTo({
								url: url
							})
						} else {
							uni.navigateTo({
								url: '/pages/main/bind?type=' + 'employee'
							})
						}
					} else if (name == 'AboutUs') {
						uni.navigateTo({
							url: url
						})
					} else if (name == 'MyOrder') {
						uni.navigateTo({
							url: url
						})
					}
				} else {
					if (this.$i18n.locale == 'cn') {
						uni.showToast({
							title: '待开发 !',
							icon: "none",
							duration: 3000,
						})
					} else {
						uni.showToast({
							title: 'ياسىلۋاتىدۇ',
							icon: "none",
							duration: 3000,

						})
					}
				}


			},
			changeshop() {
				uni.navigateTo({
					url: '/pages/boos/main'
				})
			},
			changeemployee() {
				uni.navigateTo({
					url: '/pages/employee/main'
				})
			},
			changeMobile(mobile) {
				uni.makePhoneCall({
					phoneNumber: mobile
				})

			},
			// 时间处理函数
			daysBetweenDates(date1, date2) {
				const d1 = new Date(date1);
				const d2 = new Date(date2);
				return (d2 - d1) / (24 * 3600 * 1000);
			}

		}
	}
</script>

<style lang="scss" scoped>
	.me-box {
		width: 100%;
		height: 100%;
		padding-bottom: 300rpx;

		.me-header {
			width: 100%;
			height: 330rpx;

			background-repeat: no-repeat;
			background-size: 100% 100%;
			background-color: $uni-color-topic;
			display: flex;
			justify-content: center;
			// align-items: center;
			border-radius: 0rpx 0rpx 15rpx 15rpx;

			.user-box {
				display: flex;
				flex-direction: column;
				align-items: center;
				margin-top: 30rpx;

				.avartar {
					width: 120rpx;
					height: 120rpx;
					border-radius: 100%;
					background-color: rgba(0, 0, 0, 0.2);

					image {
						width: 100%;
						height: 100%;
						border-radius: 100%;
					}
				}

				.username {
					color: #fff;
					font-size: $uni-font-size-lg;
					margin-top: $uni-spacing-margin-sm;
				}

				.time {
					color: #fff;
					font-size: $uni-font-size-lg;
					// margin-top: 10rpx;
				}
			}
		}

		.menu-box {
			width: 100%;
			padding: 0rpx 30rpx;
			margin-top: -70rpx;
			box-sizing: border-box;

			.top-menu {
				width: 100%;
				display: flex;
				justify-content: space-around;
				align-items: center;
				background-color: #fff;
				border-radius: $uni-border-radius-lg;
				padding: 40rpx $uni-spacing-padding-sm;
				box-sizing: border-box;
				color: $uni-color-title;
				font-size: $uni-font-size-sm1 ;
				box-shadow: $uni-bg-shadow;
				font-weight: 500;

				.item {
					display: flex;
					flex-direction: column;
					align-items: center;

					.icon {}

					.item-title {
						padding-top: 10rpx;
						padding-bottom: 10rpx;
					}
				}
			}

			.footer-menu {
				width: 100%;
				box-sizing: border-box;
				margin-top: 30rpx;

				.item {
					display: flex;
					justify-content: space-between;
					align-items: center;
					box-sizing: border-box;
					padding: 30rpx 20rpx;
					// border-bottom: 1rpx solid $uni-border-color;
					color: $uni-color-title;
					font-size: $uni-font-size-sm1 ;
					border-radius: $uni-border-radius-lg;
					margin-top: $uni-spacing-margin-sm;
					background-color: $uni-text-color-inverse;
					box-shadow: $uni-bg-shadow;
					font-weight: 500;
					border: none !important;

					.title {
						display: flex;
						align-items: center;

						text {
							padding: 0rpx 20rpx;

						}
					}

					.icon-box {
						padding: 15rpx;
						background-color: $uni-color-topic;
						box-shadow: $uni-bg-shadow;
						border-radius: $uni-border-radius-base;

					}
				}
			}

		}
	}

	.pop-box {
		width: 400rpx;
		height: 400rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		border-radius: 30rpx;

		.time {
			color: #000;
			padding: 10rpx 0rpx;
		}
	}

	button {
		position: relative;
		display: block;
		margin-left: auto;
		margin-right: auto;
		padding-left: 0px;
		padding-right: 0px;
		box-sizing: border-box;
		// font-size: 18px;
		text-align: center;
		text-decoration: none;
		// line-height: 1;
		line-height: 1.35;
		// border-radius: 5px;
		-webkit-tap-highlight-color: transparent;
		overflow: hidden;
		color: #000000;
		background-color: #fff;
		width: 100%;
		height: 100%;
	}

	button::after {
		border: none;
	}
</style>